<!DOCTYPE html>
<html>
	<?php header('Content-Type: text/html; charset=utf-8');?>
	<head>
		<meta charset="UTF-8">
		<title>欢迎页面-L-admin1.0</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
		<link rel="shortcut icon" href="../images/titlelogo.png" type="image/x-icon" />
		<link rel="stylesheet" href="../css/font.css">
		<link rel="stylesheet" href="../css/xadmin.css">
		<script src="../js/jquery-3.3.1.min.js"></script>
		<script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="../js/xadmin.js"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

		<!-- <script src="http://www.jq22.com/jquery/jquery-3.3.1.js"></script> -->

		<link href="../lib/layui/css/layui.css" type="text/css" rel="stylesheet">
		<script language="Javascript" src="../js/nicePage.js"></script>


		<script src="../js/cpexcel.js"></script>
		<script src="../js/shim.js"></script>
		<script src="../js/jszip.js"></script>
		<script src="../js/xlsx.js"></script>

		<?php $host="localhost";  //IP地址
$username="root";  //数据库用户名
$password="root"; //数据库密码
$port=3306;       //端口
$dbname="xops"; //数据库名称
//连接数据库
$con = mysqli_connect($host.":".$port,$username,$password,$dbname);

if ($con->connect_error) {
   die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);

}
 $l=5;
$con->query("set names utf8"); // 设置输出字符集
         $sql_se="Select * from `user`  ";
         $result_se=mysqli_query($con,$sql_se);
         $count_se= mysqli_num_rows($result_se);
				  $newru=[];
     while ($rowru=mysqli_fetch_assoc($result_se)) {
        $newru[]=$rowru;
      }
      // echo "ji:".$newru[0]['json'];

?>
	</head>
	<style>
		* { margin: 0; padding: 0; }
 
  body { font-family: 'Microsoft Yahei'; font-size: 18px; background-color: #f8f8f8; }
  
  #table2 {
    width: 1200px;
    margin: 40px auto 0;
    border-collapse: collapse;
    background-color: #fff;
  }
  #table td,
  #table th {
  /*  padding: 0.75em 1.5em; */
  }
  #table thead {
    color: #fff;
    background-color: #31bc86;
  }
  #table thead th {
    text-align: left;
  }
  #table tbody {}
  #table tbody tr {
    border-bottom: 2px dashed #000;
    cursor: default;
    transition: all .125s ease-in-out;
  }
  #table tbody tr:hover {
    background-color: cornflowerblue;
  }
  #table tbody tr.event-bgColor {
    background-color: rgba(255, 192, 203, .2);
  }
  #table tbody tr.default-bgColor {
    background-color: #fff;
  }
  #table tbody tr.hover-bgColor {
    background-color: rgba(255, 192, 203, .8);
  }
  #table tbody tr.selected-bgColor {
    background-color: rgb(255, 192, 203);
  }
  
  #selectAll {
    margin-left: -4px;
  }
  .checkbox {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -o-user-select: none;
    user-select: none;
  }
  .a-upload {
  position: relative;
    display: inline-block;

    border: 1px solid #99D3F5;

    overflow: hidden;

    text-decoration: none;
    text-indent: 0;
}
.a-upload  input {
    position: absolute;
    font-size: 20px;
    right: 0;
    top: 0;
    opacity: 0;

}

.a-upload:hover {
     background: #AADFFD;
    border-color: #78C3F3;
    color: #004974;
    text-decoration: none;

}
     
   	.content{
   		outline-style: none ;
   		    border: 0px solid #ccc;
   		    bordHer-radius: 3px;
   		    font-size: 20px;
               width: 100%;
   		padding:5px 0px; 
           margin: -10px 0px;
   		color: blue;
   	}
   
   .content2{
       border-color: red;
       outline: 0;
       -webkit-box-shadow: inset 0 1px 1px  red,0 0 8px  yellow;
       box-shadow: inset 0 1px 1px  red,0 0 8px  yellow;
   }
  </style>
	<body class=" layui-fluid">

		<!-- <div id="demo21"></div> -->
		<!-- <script src="../lib/layui/layui.js"></script> -->
		<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

		<script>



			layui.use(['laypage', 'layer'], function() {
				var laypage = layui.laypage,
					layer = layui.layer;

			
	     		laypage.render({
	     	elem: 'demo21',
	     	count: <?php echo $count_se;?>,
				limit:<?php echo $l;?>,
	     	layout: [],
	     	jump: function(obj) {
	          curr=obj.curr;
	     		// console.log(obj.curr)
					
	     	}
	     });

				
			});
		</script>
		<script>

			arr_id=[];
			jsonttp='[';
 	        
            	<?php for($i=0;$i<$count_se;$i++){ 
            	$value_se=$newru[$i]['id'];
				$value_da=$newru[$i]['account'];
				$value_un=$newru[$i]['password']; 
				$value_tel=$newru[$i]['tel']; 
				$value_dt=$newru[$i]['datetime'];
				$tt=$i+1;
				?>
				$p=1;
            arr_id.push(<?php echo $value_se;?>);
  jsonttp+="{'1':'<input type=\"checkbox\" value=\"<?php echo $value_se;?>\" name=\"test\"  style=\"width:16px;height:16px;\" class=\"layui-form-checkbox\" />'+'<span style=\"font-size:20px;margin-left:5px;\">'+ ($p++)+'</span>','4':'<input value=<?php echo $value_tel;?> class=\"content\" style=\"margin:0px;\" readonly=\"readonly\" id=<?php echo $tt;?>tel  onchange=\"change(this.id)\" />','2':'<input value=<?php echo $value_da;?> class=\"content\" style=\"margin:0px;\" readonly=\"readonly\" id=<?php echo $tt;?>at  onchange=\"change(this.id)\" />','3':'<input  type=\"password\" value=<?php echo $value_un;?> class=\"content  pwd\" style=\"margin:0px;\" readonly=\"readonly\" id=<?php echo $tt;?>pd  onchange=\"change(this.id)\" />','5':'<span style=\"font-size:20px;margin-left:5px;\"><?php echo $value_dt;?></span>'},";
            <?php }?>
              
		
			jsontt="[";
			jsontt="<?php for($i=0;$i<2;$i++){} 
			 ?>";
		
			jsonttp=jsonttp.substring(0,jsonttp.length-1)+"]";	
	     
			 jsont = eval("(" + jsonttp + ")");
	
			// 	//nameList与widthList的数组长度要一致
			var nameList = ['<input type="checkbox"   id=\"it\"  style=\"width:16px;height:16px;\" onclick=\"cb()\"  class=\"layui-form-checked\"/> <span style=\"font-size: 20px;\">序号</span>',  '<span style=\"font-size: 20px;\">用户名</span>', '<span style=\"font-size: 20px;\">密码</span>', '<span style=\"font-size: 20px;\">电话</span>','<span style=\"font-size: 20px;\">注册时间</span>'] //table的列名
			var widthList = [30, 80, 80,120,120] //table每列的宽度
			

		function cb(){
			var all=document.getElementById("it");//获取到点击全选的那个复选框的id
			      var one=document.getElementsByName("test");//获取到复选框的名称
			      if(all.checked==true){//因为获得的是数组，所以要循环 为每一个checked赋值
			          for(var i=0;i<one.length;i++){
			              one[i].checked=true;
			          }
			 
			      }else{
			          for(var j=0;j<one.length;j++){
			              one[j].checked=false;
			          }
			      }
		
		}

		
			
				
				 	nicePage.setCfg({
				 		table: 'table',
				 		bar: 'pageBar',
				 		limit:10,
				 		color: '#1E9FFF',
				 		layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
				 	});
				
				
			ge=[];
			
			function change(event){
				ge.push(event)
				alert("d:"+ge.length+" "+$("#"+event).val())
			}
			
      function btn(){
		   
		len=$("#bn").val().length;
		 var str=$("#bn").val().substring(1,3);
		// alert("q:"+len+" "+str.length)
		 if(str=="编辑"){
			 // alert("111")
			  $(".pwd").removeAttr('type')
			 $(".content").removeAttr('readonly')
			   $("#bn").val("保存");
		 $(".content").addClass('content2',true)
		 }else{
			 // alert("222")
			  $(".pwd").attr('type',"password")
			 $(".content").attr('readonly',true)
			  $(".content").removeClass('content2')
			   $("#bn").val("编辑");
			   var array = [];
			    arr_value=[];
			   for (var i = 0; i < ge.length; i++) {
			       if (array .indexOf(ge[i]) === -1) {
			           array .push(ge[i])
					   // alert("ki:"+i+" "+ge[i])
					   arr_value.push($("#"+ge[i]).val())
			       }
			   }
			   if(array.length>0){
			   	 alert("结果："+arr_value.join(",")+ " <br/>"+array.join(",")+"<br/>"+arr_id.join(","))
				 $.post("http://localhost:86/HBuilder/xops/Back.php",{
					     
					     type:"User",
						 operation:"update",
					     account:array.join(","),
						 password:arr_value.join(","),
						 phone:arr_id.join(","),
						 token:"1ab66e59325257b60b971d4afa1505ce"
					     
					   },function(data,status){
						  
						   obj=JSON.parse(data);
						    // alert("data:"+obj.code);
						   if(obj.code==200){
							    layer.msg('保存成功!',{icon:1,time:1500});
						   }else if(obj.code==202){
							    layer.msg('保存失败!',{icon:1,time:1500})
						   }
						   })
		 }
		 }

   
		//  pp=[{'1':'<input type=\"checkbox\" value="33" name=\"test\"  style=\"width:16px;height:16px;\" />','2':'eee','3':'hhhhhhhh','4':'jjjjjjj','5':'kb'}];
		// var jsont22=jsont.concat(pp);
		
    }
			 			</script>

		<div style="margin-top: 3%;margin-left: 2%;margin-right: 3%;">
			<div class="layui-form layui-col-md12 x-so">
				<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>删除</button>
				<button class="layui-btn " onclick="x_admin_show('添加用户','./member-add.html',600,400)"><i class="layui-icon"></i>添加</button>
				<input type="button" value="&#xe642;编辑" class="layui-btn layui-icon" id="bn" onclick="btn()" />&nbsp;&nbsp;
				<input type="text" name="username" placeholder="关键字" autocomplete="off" class="layui-input">
				<button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
				&nbsp;&nbsp;

				<a href="javascript:;" class="a-upload layui-btn">
					<input type="file" name="xlfile" id="xlf" multiple="multiple"><i class="iconfont">&#xe73f;</i>&nbsp;导入
				</a>

				<button class="layui-btn"><i class="iconfont">&#xe69e;</i>&nbsp;导出</button> &nbsp;&nbsp;
				<button class="layui-btn"><i class="iconfont">&#xe69e;</i>&nbsp;下载模板</button> &nbsp;&nbsp;
				<span>
					<a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);"
					 title="刷新">
						<i class="layui-icon" style="line-height:38px">ဂ</i></a>
				</span>
			</div>

			<div id="dt">
				<div id="table"></div>
				<div id="pageBar"></div>
			</div>


			<div class="x-body">
				<div class="layui-row">

				</div>

				<table class="layui-table">

				</table>
				<div class="page">
					<div id="demo21"></div>

				</div>

			</div>
		</div>


		<script>
			layui.use('laydate', function() {
				var laydate = layui.laydate;

				//执行一个laydate实例
				laydate.render({
					elem: '#start' //指定元素
				});




				//执行一个laydate实例
				laydate.render({
					elem: '#end' //指定元素
				});
			});


			/*用户-删除*/
			function member_del(obj, id) {
				layer.confirm('确认要删除吗？', function(index) {
					//发异步删除数据
					$(obj).parents("tr").remove();
					layer.msg('已删除!', {
						icon: 1,
						time: 1000
					});
				});
			}


			function delAll(argument) {


				var id = document.getElementsByName('test');
				var value = new Array();
				for (var i = 0; i < id.length; i++) {
					if (id[i].checked)
						value.push(id[i].value);
				}
				if (value.length != 0) {
					layer.confirm('确认要删除吗？', function(index) {
						//捉到所有被选中的，发异步进行删除
						// for(var p=0;p<value.length;p++){
						// 	jsont.splice(parseInt(jsont[p]-1),1)
						// 	alert("gg:"+jsont.length)
						// }

						$.post("http://localhost:86/HBuilder/xops/Back.php", {

							type: "User",
							operation: "del",
							account: value.join(','),

							token: "1ab66e59325257b60b971d4afa1505ce"

						}, function(data, status) {
							obj = JSON.parse(data);

							if (obj.code == 200) {
								// alert("pp:"+data)	
								// arr_ss=obj.data.split(",");
								// alert("uu:"+arr_ss.length+" "+arr_ss[0])
								// for(var j=0;j<arr_ss.length;j++){
								// 	jsont.splice(parseInt(arr_ss[j]-1),1)
								// 	alert("gg:"+jsont.length)
								// }

								// $("#table").load(location.href+" #table");
								layer.alert('删除成功！', {
									icon: 1
								}, function(index) {
									//发异步删除数据

									yu();

								});

								function yu() {
									window.location.href = "user.html";

								}

							} else {
								layer.msg('删除失败', {
									icon: 1
								});
							}

						})



						// $(".layui-form-checked").not('.header').parents('tr').remove();
					});
				} else {
					layer.msg('您未选择删除数据！', {
						icon: 5
					});
				}
			}
		</script>
		<script>
			var storage = null
			storage = window.sessionStorage;
			// storage.removeItem("xops123456")

			// alert("h3:" + storage.getItem("xops123456"))
			// sessionStorage.setItem("key","ff")
			// sessionStorage.clear()
			// alert("hh:"+sessionStorage.getItem("key"))

			var X = XLSX;
			var XW = {
				/* worker message */
				msg: 'xlsx',
				/* worker scripts */
				worker: 'js/xlsxworker.js'
			};

			var global_wb;
     
			var process_wb = (function() {


				function get_format() {
					return "json";
				}

				var to_json = function to_json(workbook) {
					var result = {};
					workbook.SheetNames.forEach(function(sheetName) {

						var roa = X.utils.sheet_to_json(workbook.Sheets[sheetName], {
							header: 1
						});
						// alert("dd:"+sheetName+" "+roa.length)
						if (roa.length) result["data"] = roa;
					});
					// alert("hh:"+result);
					   p_test=0;
					arr_in = [];
					title = ["用户名", "密码", "电话"];
					title_bt = ["供应商", "电话", "tel"];
					arr_bj = [];
					res_str = "[";
					var uid = 0,
						pid = 0,
						tid = 0;
					for (var i in result) {

						for (var j in result[i]) {

							// console.log("tt:", i, "--", j, "--", result[i][j])
							for (var z in result[i][j]) {
								if (j == 0) {
									for (var k in result[i][0]) {
										arr_in.push(result[i][0][k])
										switch (result[i][0][k]) {
											case "用户名":
												uid = k;
												break;
											case "密码":
												pid = k;
												break;
											case "电话":
												tid = k;
												break;
											default:
												break;
										}
										// console.log(" gggg ", uid, " ", pid, " ", tid, " ", "::", result[i][0])

									}
									break;

									// console.log(" gggg ", z, "::", result[i][0])
								}
								// console.log(i, "  ", j, "  ", z, "::", result[i][j][z])
								if (j > 0) {
									res_str += "{\"username\":\"" + result[i][j][uid] + "\",\"password\":\"" + result[i][j][pid] +
										"\",\"tel\":\"" + result[i][j][tid] + "\"},"
								}

								// alert("vv:"+" "+j+" "+z+" "+result[i][j][z])
								break;


							}
						}

					}
					res_str = res_str.substr(0, res_str.length - 1) + "]";
					// alert("str:" + res_str)
					result_str = JSON.stringify(result, 2, 2);
                   
					 
					
					var c = isContained(arr_in, title);
					// alert("rre:" + arr_in.join(",") + " " + arr_in.length+"--")
					if (!c) {
						alert("缺少标题栏：" + arr_bj.join(" "))
					     p_test=1; 
					} else {

						var storage = null;
						if (window.sessionStorage) { //判断浏览器是否支持localStorage
							storage = window.sessionStorage;
							storage.setItem("xops123456", res_str); //调用setItem方法，存储数据
							alert("wmmen" + storage.getItem("xops123456")); //调用getItem方法，弹框显示 name 为 Rick


						} else {
							alert("您的浏览器不支持导入，请重新换个浏览器！")
							// $.post("http://localhost:86/HBuilder/xops/Back.php",{
							// 	type:"Config",
							// 	operation:
							// 	
							// },function(data,status){
							// 	alert("falst:"+data)
							// })

						}
					}
				
					// sessionStorage.setItem("xops123456",result_str)
					
					// alert("h33:" + sessionStorage.getItem("xops123456"))
					return JSON.stringify(result['data'], 2, 2);
				};



				return function process_wb(wb) {
					global_wb = wb;
					var output = "";

					switch (get_format()) {

						case "json":
							output = to_json(wb);
							break;

					}
					
					// if(p_test==0){					
					
                  if(typeof($("#xlf").attr("onclick"))=="undefined"  && p_test==0){
					    
						$("#xlf").attr("onclick", "x_admin_show('添加数据','./daoru-excel.html',800,600)");
						$('#xlf').trigger("click");
						$("#xlf").removeAttr("onclick")
						// alert("succ")
						
						}else{
							$("#xlf").removeAttr("onclick")
						
						}


					// console.log("gg22:", output)
					// }

					// window.location.href="x_admin_show('添加用户','./admin-add.html',600,400)";

					// console.log("output", new Date());
				};
			})();



			function isContained(aa, bb) {
				if (!(aa instanceof Array) || !(bb instanceof Array) || ((aa.length < bb.length))) {
					return false;
				}
				var aaStr = aa.toString();
				// alert("len:"+aaStr)
				for (var i = 0; i < bb.length; i++) {

					if (aaStr.indexOf(bb[i]) < 0) {
						arr_bj.push(bb[i])
					}

				}
				if (arr_bj.length > 0)
					return false;
				return true;
			}

			var do_file = (function() {
				var rABS = typeof FileReader !== "undefined" && (FileReader.prototype || {}).readAsBinaryString;


				return function do_file(files) {
					rABS = false;
					use_worker = false;
					var f = files[0];
					var reader = new FileReader();
					reader.onload = function(e) {
						if (typeof console !== 'undefined') console.log("onload", new Date(), rABS, use_worker);
						var data = e.target.result;

						if (!rABS) data = new Uint8Array(data);
						if (use_worker) xw(data, process_wb);
						else process_wb(X.read(data, {
							type: rABS ? 'binary' : 'array'
						}));
					};
					if (rABS) reader.readAsBinaryString(f);
					else reader.readAsArrayBuffer(f);
				};
			})();


			(function() {
				var xlf = document.getElementById('xlf');
				if (!xlf.addEventListener) return;

				function handleFile(e) {
					do_file(e.target.files);
				}
				xlf.addEventListener('change', handleFile, false);
			})();
			var _gaq = _gaq || [];
			_gaq.push(['_setAccount', 'UA-36810333-1']);
			_gaq.push(['_trackPageview']);
		</script>
	</body>

</html>
